package cn.msxb.clustersession.conf.intercetpor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 用户权限拦截器
 */
public class UserAuthInterceptor implements HandlerInterceptor {

    @Override
    // 前置拦截器
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object  sessionId = request.getSession().getAttribute("sessionId");
        if (sessionId != null && session.getId().equals(sessionId)) {
            return true;
        }
        response.sendRedirect("/cluster-session-redis/test/login");
        return false;
    }
}
